package java8.methodref;

import java.util.*;

/**
 * @author 周宇
 * @create 2020-05-19 18:12
 */
public class EmployeeSort {
    public static void main(String[] args) {
        List<Employee> employeeList = new ArrayList<>();
        employeeList.add(new Employee("张三棍", 003));
        employeeList.add(new Employee("魏二金", 002));
        employeeList.add(new Employee("赵五通", 005));
        employeeList.add(new Employee("陈一龙", 001));
        employeeList.add(new Employee("李四万", 004));
        Collections.sort(employeeList, (o1, o2) -> o1.getEno().compareTo(o2.getEno()));
        System.out.println(employeeList);

        Employee[] employees = new Employee[5];
        employees[0] = new Employee("张三棍", 003);
        employees[1] = new Employee("魏二金", 002);
        employees[2] = new Employee("赵五通", 005);
        employees[3] = new Employee("陈一龙", 001);
        employees[4] = new Employee("李四万", 004);
        Arrays.sort(employees);
        System.err.println(Arrays.toString(employees));

        employees[0] = new Employee("张三棍", 003);
        employees[1] = new Employee("魏二金", 002);
        employees[2] = new Employee("赵五通", 005);
        employees[3] = new Employee("陈一龙", 001);
        employees[4] = new Employee("李四万", 004);
        Arrays.sort(employees, Employee::compareByEno);//静态方法引用
        System.out.println(Arrays.toString(employees));

        //再简化，便于理解
        List<Integer> list = Arrays.asList(11, 22, 34, 55, 7);
        list.sort(Integer::compareTo);//静态方法引用
        System.out.println(list);
    }
}